package test.desktop;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.SwingUtilities;

public class MenuExample extends JFrame {
	
	public MenuExample() {
		initUI();
	}
	
	public void initUI() {
		
		setTitle("Menu Example");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(300, 200);
		
		JMenuBar menuBar = new JMenuBar();
		ImageIcon exitIcon = new ImageIcon("images/menu/icons/Exit.png");
	
		JMenu file = new JMenu("File");
		file.setMnemonic(KeyEvent.VK_F);
		
		JMenuItem exitItem = new JMenuItem("Exit", exitIcon);
		exitItem.setMnemonic(KeyEvent.VK_X);
		exitItem.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				System.exit(0);
			}
			
		});
		
		file.add(exitItem);
		menuBar.add(file);
		
		setJMenuBar(menuBar);
	}
	
	public static void main(String[] args) {
		
		SwingUtilities.invokeLater(new Runnable() {
			@Override
			public void run() {
				new MenuExample().setVisible(true);
			}
		});
	}
}
